import {createRouter, createWebHashHistory} from 'vue-router'
import vuex from "../store/index.js";
import {ElMessage} from "element-plus";
import Login from "../views/Login.vue";
import Main from "../views/Main.vue";
import DashBoard from "../views/DashBoard.vue";
import Personal from "../views/personal/Personal.vue";
import PersonalUpdate from "../views/personal/PersonalUpdate.vue";
import Emp from "../views/ums/emp/Emp.vue";
import EmpInsert from "../views/ums/emp/EmpInsert.vue";
import EmpUpdate from "../views/ums/emp/EmpUpdate.vue";
import EmpUpdateRoles from "../views/ums/emp/EmpUpdateRoles.vue";
import Dept from "../views/ums/dept/Dept.vue";
import DeptInsert from "../views/ums/dept/DeptInsert.vue";
import DeptUpdate from "../views/ums/dept/DeptUpdate.vue";
import Role from "../views/ums/role/Role.vue";
import RoleInsert from "../views/ums/role/RoleInsert.vue";
import RoleUpdate from "../views/ums/role/RoleUpdate.vue";
import RoleUpdateMenus from "../views/ums/role/RoleUpdateMenus.vue";
import Menu from "../views/ums/menu/Menu.vue";
import MenuInsert from "../views/ums/menu/MenuInsert.vue";
import MenuUpdate from "../views/ums/menu/MenuUpdate.vue";
import SubMenu from "../views/ums/menu/sub-menus/SubMenu.vue";
import SubMenuInsert from "../views/ums/menu/sub-menus/SubMenuInsert.vue";
import SubMenuUpdate from "../views/ums/menu/sub-menus/SubMenuUpdate.vue";
import Direction from "../views/cms/direction/Direction.vue";
import DirectionInsert from "../views/cms/direction/DirectionInsert.vue";
import DirectionUpdate from "../views/cms/direction/DirectionUpdate.vue";
import Student from "../views/cms/student/Student.vue";
import StudentInsert from "../views/cms/student/StudentInsert.vue";
import StudentUpdate from "../views/cms/student/StudentUpdate.vue";
import Clazz from "../views/cms/clazz/Clazz.vue";
import ClazzInsert from "../views/cms/clazz/ClazzInsert.vue";
import ClazzUpdate from "../views/cms/clazz/ClazzUpdate.vue";
import CheckAttendance from "../views/cms/attendance/CheckAttendance.vue";
import Attendance from "../views/cms/attendance/Attendance.vue";
import Room from "../views/cms/room/Room.vue";
import RoomInsert from "../views/cms/room/RoomInsert.vue";
import RoomUpdate from "../views/cms/room/RoomUpdate.vue";
import CourseStages from "../views/cms/stages/CourseStages.vue";
import CourseStagesInsert from "../views/cms/stages/CourseStagesInsert.vue";
import CourseStagesUpdate from "../views/cms/stages/CourseStagesUpdate.vue";
import Course from "../views/cms/course/Course.vue";
import CourseInsert from "../views/cms/course/CourseInsert.vue";
import CourseUpdate from "../views/cms/course/CourseUpdate.vue";
import Schedule from "../views/cms/schedule/Schedule.vue";
import ScheduleUpdate from "../views/cms/schedule/ScheduleUpdate.vue";
import ScheduleInsert from "../views/cms/schedule/ScheduleInsert.vue";
import ScheduleBatchInsert from "../views/cms/schedule/ScheduleBatchInsert.vue";


const routes = [
    {path: '/', name: 'Login', component: Login},
    {
        path: '/Main', name: 'Main', component: Main,
        redirect: '/DashBoard',
        children: [
            {path: '/DashBoard', name: 'DashBoard', component: DashBoard},
            {path: '/Personal', name: 'Personal', component: Personal},
            {path: '/PersonalUpdate', name: 'PersonalUpdate', component: PersonalUpdate},
            {path: '/Emp', name: 'Emp', component: Emp},
            {path: '/EmpInsert', name: 'EmpInsert', component: EmpInsert},
            {path: '/EmpUpdate', name: 'EmpUpdate', component: EmpUpdate},
            {path: '/EmpUpdateRoles', name: 'EmpUpdateRoles', component: EmpUpdateRoles},
            {path: '/Dept', name: 'Dept', component: Dept},
            {path: '/DeptInsert', name: 'DeptInsert', component: DeptInsert},
            {path: '/DeptUpdate', name: 'DeptUpdate', component: DeptUpdate},
            {path: '/Role', name: 'Role', component: Role},
            {path: '/RoleInsert', name: 'RoleInsert', component: RoleInsert},
            {path: '/RoleUpdate', name: 'RoleUpdate', component: RoleUpdate},
            {path: '/RoleUpdateMenus', name: 'RoleUpdateMenus', component: RoleUpdateMenus},
            {path: '/Menu', name: 'Menu', component: Menu},
            {path: '/MenuInsert', name: 'MenuInsert', component: MenuInsert},
            {path: '/MenuUpdate', name: 'MenuUpdate', component: MenuUpdate},
            {path: '/SubMenu', name: 'SubMenu', component: SubMenu},
            {path: '/SubMenuInsert', name: 'SubMenuInsert', component: SubMenuInsert},
            {path: '/SubMenuUpdate', name: 'SubMenuUpdate', component: SubMenuUpdate},
            {path: '/Direction', name: 'Direction', component: Direction},
            {path: '/DirectionInsert', name: 'DirectionInsert', component: DirectionInsert},
            {path: '/DirectionUpdate', name: 'DirectionUpdate', component: DirectionUpdate},
            {path: '/Student', name: 'Student', component: Student},
            {path: '/StudentInsert', name: 'StudentInsert', component: StudentInsert},
            {path: '/StudentUpdate', name: 'StudentUpdate', component: StudentUpdate},
            {path: '/Club', name: 'Clazz', component: Clazz},
            {path: '/ClazzInsert', name: 'ClazzInsert', component: ClazzInsert},
            {path: '/ClazzUpdate', name: 'ClazzUpdate', component: ClazzUpdate},
            {path: '/Attendance', name: 'Attendance', component: Attendance},
            {path: '/CheckAttendance', name: 'CheckAttendance', component: CheckAttendance},
            {path: '/Room', name: 'Room', component: Room},
            {path: '/RoomInsert', name: 'RoomInsert', component: RoomInsert},
            {path: '/RoomUpdate', name: 'RoomUpdate', component: RoomUpdate},
            {path: '/CourseStages', name: 'CourseStages', component: CourseStages},
            {path: '/CourseStagesInsert', name: 'CourseStagesInsert', component: CourseStagesInsert},
            {path: '/CourseStagesUpdate', name: 'CourseStagesUpdate', component: CourseStagesUpdate},
            {path: '/Course', name: 'Course', component: Course},
            {path: '/CourseInsert', name: 'CourseInsert', component: CourseInsert},
            {path: '/CourseUpdate', name: 'CourseUpdate', component: CourseUpdate},
            {path: '/Schedule', name: 'Schedule', component: Schedule},
            {path: '/ScheduleUpdate', name: 'ScheduleUpdate', component: ScheduleUpdate},
            {path: '/ScheduleInsert', name: 'ScheduleInsert', component: ScheduleInsert},
            {path: '/ScheduleBatchInsert', name: 'ScheduleBatchInsert', component: ScheduleBatchInsert},
        ]
    },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
});

/*
 * 路由前置守卫：每次转发路由前执行的函数
 * param to: 来源地址
 * param from: 目标地址
 * next: 放行函数
 */
router.beforeEach((to, from, next) => {
    // 登录页面或已登录状态，均直接放行
    if (to.path === '/' || vuex.state['loginFlag']) {
        next();
    }
    // 其余情况直接跳转回登录页面
    else {
        ElMessage.warning('请先登录！');
        setTimeout(() => next('/'), 2000);
    }
});


export default router